package com.xyzboom.compiler.excepitons.compiler.lexer

open class IllegalLexerException protected constructor(s: String) : Exception(s) {
    companion object {
        fun expectRuleNameAndType(i: Int) = ExpectRuleNameAndTypeException(i, "expect token name at line $i")
        fun lackOfChar(c: Char, line: Int) =
            LackOfCharException(c, line, "IllegalLexerRegex: lack of '$c' at line $line in expression!")

        fun noSuchRuleException(line: Int, lineIndex: Int, tokenWantName: String, lineStr: String)
                : NoSuchRuleException {
            val messageSb = StringBuilder("NoSuchToken: $tokenWantName at line $line\n")
            messageSb.append("\t$lineStr\n\t")
            for (i in 0 until lineIndex) {
                messageSb.append(' ')
            }
            for (i in lineIndex until (lineIndex + tokenWantName.length)) {
                messageSb.append('^')
            }
            return NoSuchRuleException(line, lineIndex, tokenWantName, messageSb.toString())
        }
    }
}